<!DOCTYPE html>
<html>

<head>
  <link rel="shortcut icon" href="#" />
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title>JetBrains 注册机 + TLS 服务授权认证(By johnroot)</title>
  <style type="text/css">
    /* 全局样式重置与基础设置 */
    * {
      margin: 0;
      padding: 0;
      box-sizing: border-box;
      font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Helvetica Neue', Arial, sans-serif;
    }
    
    body {
      background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
      color: #333;
      line-height: 1.6;
      min-height: 100vh;
    }
    
    /* 主容器样式 */
    .container {
      display: flex;
      min-height: 100vh;
      max-width: 1400px;
      margin: 0 auto;
      background: rgba(255, 255, 255, 0.95);
      backdrop-filter: blur(10px);
      box-shadow: 0 20px 40px rgba(0,0,0,0.1);
      border-radius: 20px;
      overflow: hidden;
      margin-top: 20px;
      margin-bottom: 20px;
    }
    
    /* 侧边栏样式 */
    .sidebar {
      width: 280px;
      flex-shrink: 0;
      background: linear-gradient(180deg, #1e3c72 0%, #2a5298 100%);
      padding: 30px 0;
      color: white;
      position: relative;
    }
    
    .sidebar::before {
      content: '';
      position: absolute;
      top: 0;
      left: 0;
      right: 0;
      bottom: 0;
      background: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><defs><pattern id="grain" width="100" height="100" patternUnits="userSpaceOnUse"><circle cx="50" cy="50" r="1" fill="%23ffffff" opacity="0.05"/></pattern></defs><rect width="100" height="100" fill="url(%23grain)"/></svg>') repeat;
      pointer-events: none;
    }
    
    .sidebar h3 {
      padding: 0 30px 20px;
      margin-bottom: 25px;
      border-bottom: 2px solid rgba(255,255,255,0.2);
      font-size: 20px;
      font-weight: 700;
      letter-spacing: 1px;
      text-transform: uppercase;
      position: relative;
      z-index: 1;
    }
    
    .sidebar ul {
      list-style-type: none;
      position: relative;
      z-index: 1;
    }
    
    .sidebar li {
      margin-bottom: 8px;
    }
    
    .sidebar a {
      text-decoration: none;
      color: rgba(255,255,255,0.9);
      padding: 15px 30px;
      display: block;
      transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
      border-left: 4px solid transparent;
      font-weight: 500;
      position: relative;
      overflow: hidden;
    }
    
    .sidebar a::before {
      content: '';
      position: absolute;
      top: 0;
      left: -100%;
      width: 100%;
      height: 100%;
      background: linear-gradient(90deg, transparent, rgba(255,255,255,0.1), transparent);
      transition: left 0.5s;
    }
    
    .sidebar a:hover {
      background-color: rgba(255,255,255,0.15);
      color: white;
      transform: translateX(5px);
    }
    
    .sidebar a:hover::before {
      left: 100%;
    }
    
    .sidebar a.active {
      background: linear-gradient(90deg, rgba(255,255,255,0.2), rgba(255,255,255,0.1));
      color: white;
      border-left-color: #00d4ff;
      font-weight: 600;
      box-shadow: inset 0 0 20px rgba(255,255,255,0.1);
    }
    
    /* 内容区域样式 */
    .content {
      flex: 1;
      padding: 40px;
      background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
      position: relative;
    }
    
    .content::before {
      content: '';
      position: absolute;
      top: 0;
      left: 0;
      right: 0;
      bottom: 0;
      background: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 60 60"><defs><pattern id="hexagon" width="60" height="60" patternUnits="userSpaceOnUse"><polygon points="30,5 50,20 50,40 30,55 10,40 10,20" fill="none" stroke="%23ffffff" stroke-width="0.5" opacity="0.3"/></pattern></defs><rect width="60" height="60" fill="url(%23hexagon)"/></svg>') repeat;
      pointer-events: none;
    }
    
    .content-section {
      display: none;
      animation: slideInUp 0.6s cubic-bezier(0.4, 0, 0.2, 1);
      position: relative;
      z-index: 1;
    }
    
    .content-section.active {
      display: block;
    }
    
    /* 标题与文本样式 */
    h1 {
      color: #1e3c72;
      margin-bottom: 30px;
      font-size: 28px;
      font-weight: 700;
      padding-bottom: 15px;
      border-bottom: 3px solid #00d4ff;
      position: relative;
      text-shadow: 0 2px 4px rgba(0,0,0,0.1);
    }
    
    h1::after {
      content: '';
      position: absolute;
      bottom: -3px;
      left: 0;
      width: 60px;
      height: 3px;
      background: linear-gradient(90deg, #667eea, #764ba2);
      border-radius: 2px;
    }
    
    p {
      margin-bottom: 18px;
      line-height: 1.8;
      font-size: 15px;
    }
    
    /* 卡片样式 */
    .card {
      background: rgba(255, 255, 255, 0.9);
      border-radius: 15px;
      padding: 25px;
      margin: 20px 0;
      box-shadow: 0 10px 30px rgba(0,0,0,0.1);
      backdrop-filter: blur(10px);
      border: 1px solid rgba(255,255,255,0.2);
      transition: all 0.3s ease;
    }
    
    .card:hover {
      transform: translateY(-5px);
      box-shadow: 0 20px 40px rgba(0,0,0,0.15);
    }
    
    /* 表格样式 */
    table {
      border-collapse: collapse;
      width: 100%;
      margin: 15px 0;
      border-radius: 12px;
      overflow: hidden;
      box-shadow: 0 8px 25px rgba(0,0,0,0.1);
      background: white;
    }
    
    tr td {
      padding: 15px 20px;
      border: none;
      text-align: left;
      font-family: 'Consolas', 'Monaco', monospace;
      font-size: 13px;
      line-height: 1.6;
    }
    
    tr:nth-child(even) {
      background: linear-gradient(90deg, #f8f9fa, #e9ecef);
    }
    
    /* 表单元素样式 */
    fieldset {
      border: none;
      padding: 0;
      margin: 0;
    }
    
    legend {
      font-weight: 700;
      color: #1e3c72;
      padding: 0;
      font-size: 18px;
      margin-bottom: 20px;
      text-transform: uppercase;
      letter-spacing: 0.5px;
    }
    
    .form-group {
      display: flex;
      flex-wrap: wrap;
      gap: 20px;
      margin-bottom: 20px;
      align-items: center;
    }
    
    .form-field {
      display: flex;
      flex-direction: column;
      min-width: 200px;
      flex: 1;
    }
    
    label {
      display: block;
      margin-bottom: 8px;
      color: #2c3e50;
      font-weight: 600;
      font-size: 14px;
      text-transform: uppercase;
      letter-spacing: 0.5px;
    }
    
    input[type="text"], select, textarea {
      padding: 12px 16px;
      border: 2px solid #e1e8ed;
      border-radius: 8px;
      font-size: 14px;
      transition: all 0.3s ease;
      background: rgba(255,255,255,0.9);
      backdrop-filter: blur(5px);
    }
    
    input[type="text"]:focus, select:focus, textarea:focus {
      border-color: #667eea;
      outline: none;
      box-shadow: 0 0 0 4px rgba(102, 126, 234, 0.1);
      transform: translateY(-2px);
    }
    
    select {
      cursor: pointer;
      background-image: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="%23667eea"><path d="M7 10l5 5 5-5z"/></svg>');
      background-repeat: no-repeat;
      background-position: right 12px center;
      background-size: 20px;
      appearance: none;
    }
    
    #mkey {
      width: 100%;
      height: 140px;
      resize: vertical;
      font-family: 'Consolas', 'Monaco', monospace;
    }
    
    /* 按钮样式 */
    input[type="submit"], button {
      background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
      color: white;
      border: none;
      padding: 12px 30px;
      border-radius: 25px;
      cursor: pointer;
      font-size: 14px;
      font-weight: 600;
      text-transform: uppercase;
      letter-spacing: 1px;
      transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
      box-shadow: 0 4px 15px rgba(102, 126, 234, 0.3);
      position: relative;
      overflow: hidden;
    }
    
    input[type="submit"]:hover, button:hover {
      transform: translateY(-3px);
      box-shadow: 0 8px 25px rgba(102, 126, 234, 0.4);
    }
    
    input[type="submit"]:active, button:active {
      transform: translateY(-1px);
    }
    
    /* 结果显示区域 */
    .result-container {
      margin-top: 20px;
      border-radius: 12px;
      background: rgba(255, 255, 255, 0.95);
      backdrop-filter: blur(10px);
      overflow: hidden;
      box-shadow: 0 8px 25px rgba(0,0,0,0.1);
    }
    
    #out_pre {
      max-height: 350px;
      overflow-y: auto;
      padding: 20px;
      font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
      font-size: 13px;
      line-height: 1.6;
      white-space: pre-wrap;
      word-wrap: break-word;
      background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
    }
    
    /* 警告文本样式 */
    .text-danger {
      color: #e74c3c;
      font-weight: 600;
      background: rgba(231, 76, 60, 0.1);
      padding: 15px;
      border-radius: 8px;
      border-left: 4px solid #e74c3c;
    }
    
    /* 成功文本样式 */
    .text-success {
      color: #27ae60;
      font-weight: 600;
      background: rgba(39, 174, 96, 0.1);
      padding: 15px;
      border-radius: 8px;
      border-left: 4px solid #27ae60;
    }
    
    /* 动画效果 */
    @keyframes slideInUp {
      from {
        opacity: 0;
        transform: translateY(30px);
      }
      to {
        opacity: 1;
        transform: translateY(0);
      }
    }
    
    @keyframes pulse {
      0%, 100% {
        transform: scale(1);
      }
      50% {
        transform: scale(1.05);
      }
    }
    
    /* 滚动条样式 */
    ::-webkit-scrollbar {
      width: 8px;
    }
    
    ::-webkit-scrollbar-track {
      background: rgba(0,0,0,0.1);
      border-radius: 4px;
    }
    
    ::-webkit-scrollbar-thumb {
      background: linear-gradient(135deg, #667eea, #764ba2);
      border-radius: 4px;
    }
    
    ::-webkit-scrollbar-thumb:hover {
      background: linear-gradient(135deg, #5a6fd8, #6a4190);
    }
    
    /* 响应式调整 */
    @media (max-width: 1024px) {
      .container {
        margin: 10px;
        border-radius: 15px;
      }
      
      .sidebar {
        width: 250px;
      }
      
      .content {
        padding: 30px;
      }
    }
    
    @media (max-width: 768px) {
      .container {
        flex-direction: column;
        margin: 5px;
        border-radius: 10px;
      }
      
      .sidebar {
        width: 100%;
        padding: 20px 0;
      }
      
      .sidebar h3 {
        padding: 0 20px 15px;
        font-size: 18px;
      }
      
      .sidebar ul {
        display: flex;
        overflow-x: auto;
        padding: 0 10px 10px;
        gap: 10px;
      }
      
      .sidebar li {
        margin-bottom: 0;
        flex-shrink: 0;
      }
      
      .sidebar a {
        padding: 10px 20px;
        border-radius: 20px;
        border-left: none;
        white-space: nowrap;
      }
      
      .content {
        padding: 20px;
      }
      
      h1 {
        font-size: 24px;
      }
      
      .form-group {
        flex-direction: column;
        gap: 15px;
      }
      
      .form-field {
        min-width: 100%;
      }
    }
  </style>
</head>

<body>
  <div class="container">
    <div class="sidebar">
      <h3>🛠️ 功能菜单</h3>
      <ul>
        <li><a href="#" data-target="home" class="active">🏠 配置信息</a></li>
        <li><a href="#" data-target="getcode">🔑 生成注册码</a></li>
        <li><a href="#" data-target="dumpkey">🔍 解析注册码</a></li>
      </ul>
    </div>
    <div class="content">
      <!-- 首页内容 -->
      <div id="home" class="content-section active">
        <h1>🚀 JetBrains 注册机 + TLS 服务授权认证</h1>
        <div class="text-danger">
          ⚠️ 需配合最新 ja-netfilter 插件使用（关于 ja-netfilter 插件使用请自行搜索），使用下面的 power 配置信息并配置好。
        </div>
        <div class="card">
          <legend>🔧 Power 配置信息</legend>
          <table width="100%" style="table-layout:fixed">
            <tbody>
            <tr>
              <td style="word-wrap: break-word; word-break: break-all; white-space: pre-wrap; overflow-wrap: break-word; max-width: 100%; overflow-x: auto;">[Result] <br>;Hook RegistrationCode <br>{{ .powstr }} <br>;Hook LicenseServer<br>{{ .powstr2 }}</td>
            </tr>
            </tbody>
          </table>
        </div>
        <div class="text-success">
          ✅ 配置完成后，重启 JetBrains 产品即可享受完整功能。
        </div>
      </div>

      <!-- 生成注册码内容 -->
      <div id="getcode" class="content-section">
        <h1>🔑 生成注册码</h1>
        <form action="/getkey" method="post" enctype="multipart/form-data" name="form1" id="form1">
          <div class="card">
            <legend>📝 配置信息</legend>
            <div class="form-group">
              <div class="form-field">
                <label for="username">👤 用户名</label>
                <input name="username" type="text" id="username" value="{{ .Name }}" placeholder="请输入用户名" />
              </div>
              <div class="form-field">
                <label for="keyid">🆔 注册码ID</label>
                <input name="keyid" type="text" id="keyid" value="{{ .Id }}" placeholder="自动生成" />
              </div>
            </div>
            <div class="form-group">
              <div class="form-field">
                <label for="fallbackdate">📅 到期日期</label>
                <input name="fallbackdate" type="text" id="fallbackdate" value="{{ .Fd }}" placeholder="YYYY-MM-DD" />
              </div>
              <div class="form-field">
                <label for="code">🛠️ 产品选择</label>
                <select name="code" id="code">
                  <option value="all" {{ if eq .code "all" }}selected {{ end }}>🎯 全家桶</option>
                  <option value="II" {{ if eq .code "II" }}selected {{ end }}>💡 IntelliJ IDEA</option>
                  <option value="GO" {{ if eq .code "GO" }}selected {{ end }}>🐹 GoLand</option>
                  <option value="CL" {{ if eq .code "CL" }}selected {{ end }}>⚡ CLion</option>
                  <option value="AC" {{ if eq .code "AC" }}selected {{ end }}>🍎 AppCode</option>
                  <option value="WS" {{ if eq .code "WS" }}selected {{ end }}>🌐 WebStorm</option>
                  <option value="PS" {{ if eq .code "PS" }}selected {{ end }}>🐘 PhpStorm</option>
                  <option value="RM" {{ if eq .code "RM" }}selected {{ end }}>💎 RubyMine</option>
                  <option value="PC" {{ if eq .code "PC" }}selected {{ end }}>🐍 PyCharm</option>
                  <option value="DB" {{ if eq .code "DB" }}selected {{ end }}>🗄️ DataGrip</option>
                  <option value="RD" {{ if eq .code "RD" }}selected {{ end }}>🏍️ RiDer</option>
                  <option value="DS" {{ if eq .code "DS" }}selected {{ end }}>📊 DataSpell</option>
                  <option value="RR" {{ if eq .code "RR" }}selected {{ end }}>🦀 RustRover</option>
                </select>
              </div>
            </div>
            <div class="form-group">
              <div class="form-field">
                <label for="md">📋 MetaData</label>
                <input name="md" type="text" id="md" value="{{ .Md }}" placeholder="版本相关信息" />
              </div>
              <div class="form-field">
                <label for="hash">🔐 HASH值</label>
                <input name="hash" type="text" id="hash" value="{{ .Hs }}" placeholder="哈希值" />
              </div>
            </div>
            <div style="text-align: center; margin-top: 20px;">
              <input type="submit" value="🚀 生成注册码" />
            </div>
          </div>
          
          {{ if .sncode }}
          <div class="card">
            <legend>✨ 生成的注册码</legend>
            <table width="100%" style="table-layout:fixed">
              <tr>
                <td style="word-wrap: break-word; word-break: break-all; white-space: pre-wrap; overflow-wrap: break-word; font-family: 'Consolas', 'Monaco', monospace; font-size: 14px; line-height: 1.8; background: linear-gradient(135deg, #e8f5e8, #f0f8f0); padding: 20px; border-radius: 8px; max-width: 100%; overflow-x: auto;">{{ .sncode }}</td>
              </tr>
            </table>
            <div class="text-success" style="margin-top: 15px;">
              💡 复制上方注册码，在 JetBrains 产品中激活即可。
            </div>
          </div>
          {{ end }}
        </form>
      </div>

      <!-- 解析注册码内容 -->
      <div id="dumpkey" class="content-section">
        <h1>🔍 解析注册码</h1>
        <form action="/dumpkey" method="post" enctype="multipart/form-data" name="form1" id="form1">
          <div class="card">
            <legend>📋 输入注册码</legend>
            <div class="form-field">
              <label for="mkey">🔑 注册码内容</label>
              <textarea name="mkey" id="mkey" placeholder="请粘贴完整的注册码内容..."></textarea>
            </div>
            <div style="text-align: center; margin-top: 15px;">
              <input type="submit" name="button" id="button" value="🔍 开始解析" />
            </div>
          </div>
        </form>
        
        {{ if .crcret }}
        <div class="card">
          <legend>📊 解析结果</legend>
          <div class="{{ if contains .crcret "校验通过" }}text-success{{ else }}text-danger{{ end }}" style="word-wrap: break-word; word-break: break-all; white-space: pre-wrap; overflow-wrap: break-word;">
            {{ .crcret }}
          </div>
          {{ if .pz }}
          <div style="margin-top: 20px;">
            <h3 style="color: #1e3c72; margin-bottom: 15px;">🔧 可用 Power 配置</h3>
            <div style="background: rgba(39, 174, 96, 0.1); padding: 15px; border-radius: 8px; border-left: 4px solid #27ae60; font-family: 'Consolas', 'Monaco', monospace; font-size: 13px; line-height: 1.6; word-wrap: break-word; word-break: break-all; white-space: pre-wrap; overflow-wrap: break-word; max-width: 100%; overflow-x: auto;">{{ .pz }}</div>
          </div>
          {{ end }}
        </div>
        {{ end }}
        
        {{ if .gj }}
        <div class="card">
          <legend>📄 详细信息</legend>
          <div class="result-container">
            <pre id="out_pre"></pre>
          </div>
        </div>
        {{ end }}
      </div>
    </div>
  </div>

  <script type="text/javascript">
    // 获取URL参数
    function getUrlParam(name) {
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
        var r = window.location.search.substr(1).match(reg);
        if (r != null) return unescape(r[2]);
        return null;
    }

    // 切换页面函数
    function switchPage(targetPage) {
        // 移除所有active类
        document.querySelectorAll('.sidebar a').forEach(a => a.classList.remove('active'));
        document.querySelectorAll('.content-section').forEach(section => section.classList.remove('active'));
        
        // 添加active类到对应的链接和内容区域
        document.querySelector(`.sidebar a[data-target="${targetPage}"]`).classList.add('active');
        document.getElementById(targetPage).classList.add('active');
        
        // 更新URL参数
        history.pushState(null, null, `?page=${targetPage}`);
    }

    // 菜单切换功能
    document.querySelectorAll('.sidebar a').forEach(link => {
        link.addEventListener('click', function(e) {
            e.preventDefault(); // 阻止默认链接行为
            var targetPage = this.getAttribute('data-target');
            switchPage(targetPage);
        });
    });

    // 页面加载时根据后端传递的currentPage或URL参数显示对应内容
    window.onload = function() {
        // 优先使用后端传递的currentPage变量
        var serverPage = "{{ .currentPage }}";
        var urlPage = getUrlParam('page');
        var page = serverPage || urlPage || 'home';
        
        switchPage(page);
        
        // 如果是解析注册码页面，执行JSON格式化
        if (page === 'dumpkey') {
            try {
                var text = "{{ .gj }}";
                var result = JSON.stringify(JSON.parse(text), null, 2);
                document.getElementById("out_pre").innerText = result;
            } catch (e) {
                document.getElementById("out_pre").innerText = "解析失败: " + e.message;
            }
        }
    };
</script>
</body>

</html>